package com.kinpoway.domin;

import com.fasterxml.jackson.annotation.JsonView;
import com.kinpoway.validator.MyConstraint;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.validator.constraints.NotBlank;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import java.util.Date;

@Entity
@ApiModel(value = "User", description = "用户模型")
public class User {

    //三个数据返回视图
    public interface UserSimpleView{}

    public interface UserInfoView extends UserSimpleView{}

    public interface UserDetailView extends UserInfoView{}

    @Id
    @GeneratedValue
    @MyConstraint(message = "自定义校验")
    private Integer id;

    @ApiModelProperty("用户名")
    @NotNull(message = "姓名不能为空")
    private String username;

    @NotBlank(message = "型号字段不能为空")
    private String password;

    @NotNull(message = "年龄不能为空")
    private Integer age;

    @Past(message = "生日一定是过去的日期！")
    private Date birthday;

    private Date createTime;

    private Integer createId;

    private Date modifyTime;

    private Integer modifyId;

    @JsonView(UserSimpleView.class)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @JsonView(UserSimpleView.class)
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @JsonView(UserDetailView.class)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @JsonView(UserInfoView.class)
    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @JsonView(UserInfoView.class)
    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    @JsonView(UserDetailView.class)
    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @JsonView(UserDetailView.class)
    public Integer getCreateId() {
        return createId;
    }

    public void setCreateId(Integer createId) {
        this.createId = createId;
    }

    @JsonView(UserDetailView.class)
    public Date getModifyTime() {
        return modifyTime;
    }

    public void setModifyTime(Date modifyTime) {
        this.modifyTime = modifyTime;
    }

    @JsonView(UserDetailView.class)
    public Integer getModifyId() {
        return modifyId;
    }

    public void setModifyId(Integer modifyId) {
        this.modifyId = modifyId;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + username + '\'' +
                ", password='" + password + '\'' +
                ", age=" + age +
                ", birthday=" + birthday +
                ", createTime=" + createTime +
                ", createId=" + createId +
                ", modifyTime=" + modifyTime +
                ", modifyId=" + modifyId +
                '}';
    }
}